//
//  SearchTextField.swift
//  OnceNectar
//
//  Created by 法正磊 on 2018/2/4.
//  Copyright © 2018年 com.inwhoop. All rights reserved.
//

import UIKit

class SearchTextField: UITextField {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    override func awakeFromNib() {
        setUI()
    }
    
    func setUI() {
        self.backgroundColor = ONColor.searchBGColor
        self.placeholder = ""
        self.layer.cornerRadius = self.height / 2
        self.layer.masksToBounds = true
        self.returnKeyType = .search
        let imageView = UIImageView(image: UIImage(named: "icon_search"))
        imageView.isUserInteractionEnabled = true;
        let view = UIView()
        view.frame = CGRect(x: 0, y: 0, width: 80, height: imageView.height)
        view.backgroundColor = UIColor.blue
        view.addSubview(imageView)
        imageView.frame = CGRect(x: view.width - imageView.width, y: 0, width: imageView.width, height: imageView.height)
        self.leftView = view
        
        self.rightViewMode = .always
        let tap = UITapGestureRecognizer(target: self, action: #selector(btnClick))
        imageView.addGestureRecognizer(tap)
    }
    
    @objc func btnClick() {
        
    }
    
}
